#!/usr/bin/pythonBasics
# -*- coding: UTF-8 -*-

#Author:super

import xlrd
from weChatApi.common.apiPublicMethod import *
from weChatApi.utils.excelVarles import ExcelVarles
import json

class openExcelFile():
	'''获取文档数据类'''
	
	def __init__(self,number):
		self.number = number
	
	def getNumber(self,number):
		'''定义用户要访问第几页'''
		self.number = number
		return number
	
	def getSheet(self):
		'''返回文档中表格数据'''
		weChatApi = xlrd.open_workbook(filePath('data','企业微信api_data.xlsx'))
		return weChatApi.sheet_by_index(self.number)
	
	@property
	def getRows(self):
		'''获取总行数'''
		return self.getSheet().nrows
	
	@property
	def getCols(self):
		'''获取总列数'''
		return self.getSheet().ncols
	
	def getValue(self,row,col):
		'''获取指定行和列的数据'''
		return self.getSheet().cell_value(row,col)
	
	def getCaseID(self, row):
		'''获取第几行的用例编号信息'''
		return self.getValue(row = row, col = ExcelVarles().getCaseID)
	
	def getDes(self, row):
		'''获取第几行的描述信息'''
		return self.getValue(row = row, col = ExcelVarles().getDes)
	
	def getUrl(self, row):
		'''获取第几行的请求地址信息'''
		url = self.getValue(row = row, col = ExcelVarles().getUrl)
		if '{access_token}' in url:
			return str(url).replace('{access_token}',readContent('data','gettoken.ini'))
		else:
			return self.getValue(row = row, col = ExcelVarles().getUrl)
	
	def getMethod(self, row):
		'''获取第几行的请求方法'''
		return self.getValue(row = row, col = ExcelVarles().getMethod)
	
	def getData(self, row):
		'''获取第几行的请求参数'''
		return self.getValue(row = row, col = ExcelVarles().getData)
	
	def getEcxel(self, row):
		'''获取第几行的期望结果'''
		return self.getValue(row = row, col = ExcelVarles().getExpect)
	
	def get_Datas(self,s):
		'''根据s获取测试点,返回list集合'''
		result = []
		for item in range(1,self.getRows):
			col = self.getSheet().row_values(item)  #获取每一列的数据
			if col[0].split('-')[0] == s:
				if '{access_token}' in col[2]:
					url = str(col[2]).replace('{access_token}',readContent('data','gettoken.ini'))
					col[2]=url
				if '{access_token}' in col[4]:
					data = str(col[4]).replace('{access_token}',readContent('data','gettoken.ini'))
					col[4]=data
				result.append(col)
		return result
	
if __name__ == '__main__':
	o = openExcelFile(5)
	print(o.get_Datas('SCBM'))

